package com.yuehuanghun.admin.core.controller.monitor;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yuehuanghun.admin.core.config.util.poi.ExcelUtil;
import com.yuehuanghun.admin.core.domain.SysOperLog;
import com.yuehuanghun.admin.core.service.ISysOperLogService;
import com.yuehuanghun.framework.annotation.Log;
import com.yuehuanghun.framework.annotation.Log.BusinessType;
import com.yuehuanghun.framework.domain.PageDTO;
import com.yuehuanghun.framework.web.BaseResource;
import com.yuehuanghun.mybatis.milu.data.Sort;
import com.yuehuanghun.mybatis.milu.data.Sort.Direction;

import cn.dev33.satoken.annotation.SaCheckPermission;

/**
 * 操作日志记录
 * 
 * @author yadmin
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseResource {
	@Autowired
	private ISysOperLogService operLogService;

	@SuppressWarnings("unchecked")
	@GetMapping("/list")
	@SaCheckPermission("monitor:operlog:list")
	public PageDTO<SysOperLog> list(SysOperLog operLog) { //NOSONAR
		List<SysOperLog> list = operLogService.getByExampleAndSort(operLog, Sort.by(Direction.DESC, SysOperLog::getOperId), getPage());
		return toPage(list);
	}

	@Log(title = "操作日志", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	@SaCheckPermission("monitor:operlog:export")
	public String export(SysOperLog operLog) { //NOSONAR
		List<SysOperLog> list = operLogService.getByExample(operLog);
		ExcelUtil<SysOperLog> util = new ExcelUtil<>(SysOperLog.class);
		return util.exportExcel(list, "操作日志");
	}

	@DeleteMapping("/{operIds}")
	@SaCheckPermission("monitor:operlog:remove")
	public void remove(@PathVariable List<Long> operIds) {
		operLogService.deleteByIds(operIds);
	}

	@Log(title = "操作日志", businessType = BusinessType.CLEAN)
	@DeleteMapping("/clean")
	@SaCheckPermission("monitor:operlog:remove")
	public void clean() {
		operLogService.deleteByCriteria(p -> {
		});
	}
}
